
/* Wrapper class for priority queue implementation */

#include "includes.h"
#include <stdlib.h>
#include <stdio.h>
#include "binheap.h"

#define BASE_SIZE 200

static PriorityQueue Q;

void stcp_init() {
  Q = Initialize(BASE_SIZE);
}

struct proc_info* stcp_get_next() {
  return DeleteMin(Q);
}

long stcp_next_event_time() {
  /* Never has a context switch */
  return -1;
}

int stcp_queue_empty() {
  return IsEmpty(Q);
}  

void stcp_advance_clock(long time_step) {
  return;
}

void stcp_add_to_queue(struct proc_info *proc) {
  if (proc == NULL) {
    printf("Null proc passed to stcp_add_to_queue\n");
    exit(-1);
  }
  /* Insert into pq */
  Insert(proc, &Q);
}

void stcp_close() {
  Destroy(Q);
}

/* Prints the queue - used for debugging */
void stcp_print_queue() {
  /*pq_printq();*/
}

/* test bench for stcp scheduler 
int main() {
  struct proc_info proc[10];

  printf("Initializing the queue\n");
  stcp_init();

  printf("Printing the empty queue\n");
  stcp_print_queue();

  printf("Adding an element to the queue\n");
  proc[0].pid = 0;
  proc[0].time_remaining = 10;
  stcp_add_to_queue(&proc[0]);

  printf("Printing the contents of the queue\n");
  stcp_print_queue();

  printf("Adding an element with a lower time than current\n");
  proc[1].pid = 1;
  proc[1].time_remaining = 5;
  stcp_add_to_queue(&proc[1]);
  
  printf("Printing the contents of the queue\n");
  stcp_print_queue();


  stcp_init();
  printf("Queue is empty.  Printing contents of queue:\n");
  stcp_print_queue();
  
  printf("Adding an element to the queue...\n");
  proc[0].pid = 1001;
  proc[0].time_remaining = 500;
  stcp_add_to_queue(&proc[0]);

  printf("Printing the queue (1 element)\n");
  stcp_print_queue();

  printf("Adding another element with earlier time\n");
  proc[1].pid = 595;
  proc[1].time_remaining = 400;
  stcp_add_to_queue(&proc[1]);
  stcp_print_queue();

  printf("Adding an element with a later time than all\n");
  proc[2].pid = 31415;
  proc[2].time_remaining = 1000;
  stcp_add_to_queue(&proc[2]);
  stcp_print_queue();

  printf("Adding an element with a time in the middle\n");
  proc[3].pid = 349;
  proc[3].time_remaining = 600;
  stcp_add_to_queue(&proc[3]);
  stcp_print_queue();

  printf("Popping off a process\n");
  proc[4] = *stcp_get_next();
  printf("Got: %d, %d\n", proc[4].pid, proc[4].time_remaining);
  stcp_print_queue();
  
  
}

*/
